//
//  TestViewController1.m
//  JKXib
//
//  Created by 王冲 on 2019/7/7.
//  Copyright © 2019 王冲. All rights reserved.
//

#import "TestViewController1.h"
#import "JKShopView.h"
#import "JKModel.h"
#import "TestViewController1ViewCell.h"

@interface TestViewController1 ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) UITableView *tableview;

@property(nonatomic,strong) NSMutableArray *dataArray;

@property (strong, nonatomic) NSTimer *timer;

@end

@implementation TestViewController1

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.dataArray addObjectsFromArray:@[@"Xib测试"]];
    
    [self.view addSubview:self.tableview];
    
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTest) userInfo:nil repeats:YES];
    
    
}

- (void)timerTest
{
    NSLog(@"%s", __func__);
}

- (void)dealloc
{
    NSLog(@"%s", __func__);
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSString *cell_name = [NSString stringWithFormat:@"%@",self.dataArray[indexPath.row]];
    
    if ([cell_name isEqualToString:@"Xib测试"]) {
        
        TestViewController1 *test1Vc = [TestViewController1 new];
        [self.navigationController pushViewController:test1Vc animated:YES];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TestViewController1ViewCell * cell = [TestViewController1ViewCell cellForTableView:tableView];
    
    cell.backgroundColor = JKRandomColor;
    
    cell.labelTest.text = @"秋风用时光的旋律，用桂花的芬芳、苹果的馨香、菊花的灿烂、牵牛花的奔放、一串红的艳丽，把一望无际的田野乡村，演绎得在自然中沉醉，渲染得天地间空旷而又阳刚";

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 163;
}

-(UITableView *)tableview{
    
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, JKNaviHeight, JK_SCREEN_WIDTH, JK_SCREEN_HEIGHT-JKNaviHeight) style:UITableViewStylePlain];
        _tableview.dataSource = self;
        _tableview.delegate = self;
        
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        if (@available(iOS 11.0, *)) {
            
            _tableview.estimatedRowHeight = 0;
            _tableview.estimatedSectionFooterHeight = 0;
            _tableview.estimatedSectionHeaderHeight = 0;
            _tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            // 小于11.0的不做操作
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        
        [TestViewController1ViewCell registerForTableView:_tableview];
    }
    
    return _tableview;
}

-(NSMutableArray *)dataArray{
    
    if (!_dataArray) {
        
        _dataArray = [NSMutableArray new];
    }
    
    return _dataArray;
}



@end
